<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //分支结构
        var psw = window.prompt("请输入密码：");
        if (psw == '123456') {
            document.write("密码正确");
        }
        else {
            document.write("密码错误");
        }

        document.write("<br>");

        var hour = new Date().getHours();
        if (hour <= 19 && hour >= 12) {
            document.write("下午好");
        }
        else if (hour >= 19) {
            document.write("晚上好");
        }
        else if (hour <= 6) {
            document.write("凌晨好");
        }
        else {
            document.write("上午好");
        }

        document.write("<br>");

        //循环结构
        for (var i = 1; i <= 10; i++) {
            document.write("循环10遍<br>");
        }

        //计算1到100的和,效率低
        var sum = 0;
        for (var i = 1; i <= 100; i++) {
            sum = sum + i;
        }
        document.write("从1到100的和：" + sum);
        document.write("<br>");

        //等差数列公式求和
        document.write("从1到100的和：" + (1 + 100) * 100 / 2);
        document.write("<br>");

    </script>
</head>

<body>

</body>

</html>